<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="sj" uri="/struts-jquery-tags"%>
<%@ include file="/taglibs.jsp"%>
<%@page import="com.yaodian100.ec.campaign.entity.Campaign"%>
<s:url value="/js" var="jsPath"/>
<s:url value="/css" var="cssPath"/>
<script type="text/javascript" charset="UTF-8" src="/js/formValidator.js" charset="UTF-8"></script>
<script type="text/javascript" charset="UTF-8" src="/js/formValidatorRegex.js" charset="UTF-8"></script>
<!-- 数字验证 -->
<script type="text/javascript" charset="UTF-8" src="/js/jquery.alphanumeric.js"></script>
<!-- 月历 -->
<script type="text/javascript" charset="UTF-8" src="/js/jquery.datepick.js"></script>
<script type="text/javascript" charset="UTF-8" src="/js/jquery.datepick-zh-CN.js"></script>
<!-- 時間 -->	
<script type="text/javascript" src="${jsPath}/jquery.timePicker.js"></script>
<link rel="stylesheet" type="text/css" href="${cssPath}/timePicker.css"/>
<script type="text/javascript" charset="UTF-8" src="/js/jquery-ui-1.7.2.custom.min.js"></script>
<link rel="stylesheet" type="text/css" href="/css/jquery-ui-1.7.2.custom.css"/>
<link rel="stylesheet" type="text/css" href="/css/smoothness.datepick.css" />
<script type="text/javascript">
<!--
function customRange (){
	var startDt = $('#startDate').val(); //起始日
	var endDt = new Date(parseInt(startDt.substring(0,4),10),parseInt(startDt.substring(5,7),10)-1,parseInt(startDt.substring(8,10),10)); //結束日
	return {minDate:endDt}; 
}

$().ready( function() {
		$('#startDate').datepick({minDate: null, showOn: 'both', 
	    	buttonImageOnly: true, buttonImage: '/images/calendar.gif',numberOfMonths:2,dateFormat:"yy-mm-dd",yearRange: '-50:+50'});
		$('#endDate').datepick({minDate:new Date(), showOn: 'both', 
	    	buttonImageOnly: true, buttonImage: '/images/calendar.gif',numberOfMonths:2,beforeShow:customRange,dateFormat:"yy-mm-dd",yearRange: '-50:+50'});
		$("#startTime").timePicker();
		$("#endTime").timePicker();
		$.formValidator.initConfig({formid:"formObj",onerror:function(msg){alert(msg);},onsuccess:function(){return true;}});

		//栏位资料验证
		$("#campaignName").formValidator({
			 onfocus:"请输入活动名称",oncorrect:"请输入活动名称格式正确"}).inputValidator({
				 min:2,max:40,onerror:"活动名称名稱不能超过40个字元之间且不能为空值"});
		$("#minOrderAmount").formValidator({
			 onfocus:"最低订单金额",oncorrect:"请输入最低订单金额格式正确"}).inputValidator({
				min:0,max:100,onerror:"最低订单金额为正浮点数"}).regexValidator({
				regexp:"decmal4",datatype:"enum",
				onerror:"最低订单金额必须是正浮点数"});
		$("#discountData").formValidator({
			 onfocus:"请输入折扣 kg",oncorrect:"请输入折扣 kg格式正确"}).inputValidator({
				min:1,max:400,onerror:"折扣 kg为正整数"}).regexValidator({
				regexp:"intege1",datatype:"enum",
				onerror:"折扣 kg必须是正整数"});
		$("#minOrderAmount").numeric({allow:"."});
		$("#discountData").numeric();
		var defaultShip = $('#shipExpenseRank').val().split(",");
		if ("1,1,1,1,1,1" == $('#shipExpenseRank').val()) {
			$("#shipExpenseRankAll").attr('checked',true);
		}
		for ( i=1;i<7 ;i++) {
			if ("1" == defaultShip[i-1]) {
				$("#shipExpenseRank"+i).attr('checked',true);
			} else {
				$("#shipExpenseRank"+i).attr('checked',false);
			}
		}
		$("#submit_button").click(function(){
			var tmpShip = "";
			for ( i=1;i<7 ;i++) {
				if ($("#shipExpenseRank"+i).attr('checked')) {
					tmpShip = tmpShip +"1,";
				} else {
					tmpShip = tmpShip +"0,";
				}
			}
			$("#shipExpenseRank").val(tmpShip.substring(0,tmpShip.length-1));
			$("#formObj").submit();
		});
	});
function selectAll(formObj,obj) {
	formObj.shipExpenseRank1.checked = obj.checked ;
	formObj.shipExpenseRank2.checked = obj.checked ;
	formObj.shipExpenseRank3.checked = obj.checked ;
	formObj.shipExpenseRank4.checked = obj.checked ;
	formObj.shipExpenseRank5.checked = obj.checked ;
	formObj.shipExpenseRank6.checked = obj.checked ;
}
//-->
</script>
<h1>运费折抵活动管理</h1>
<s:actionerror />
<s:actionmessage />
<s:fielderror />
<s:form name="formObj" action="save.do" id="formObj" method="post">
<br />
<table class="tb-data" width="100%">
	<tr>
		<th>* 活动名称</th>
		<td><s:textfield name="campaign.campaignName" id="campaignName" size="40"/></td>
	</tr>
	<tr>
		<th>* 活动起始日期时间</th>
		<td>
		<input name="startDate" id="startDate" size="10" value="<fmt:formatDate value="${campaign.startDateTime}" pattern="yyyy-MM-dd"/>">
		<input name="startTime" id="startTime" size="8" value="<fmt:formatDate value="${campaign.startDateTime}" pattern="HH:mm"/>">
		</td>
	</tr>
	<tr>
		<th>* 活动结束日期时间</th>
		<td>
		<input name="endDate" id="endDate" size="10" value="<fmt:formatDate value="${campaign.endDateTime}" pattern="yyyy-MM-dd"/>">
		<input name="endTime" id="endTime" size="8" value="<fmt:formatDate value="${campaign.endDateTime}" pattern="HH:mm"/>"></td>
	</tr>
	<tr>		
		<th>* 适用会员等级</th>
		<td><s:radio list="menuMemberRank.options" name="campaign.allowMemberRank" listKey="key" listValue="value.name"/></td>
	</tr>
	<tr>		
		<th>* 适用区域</th>
		<td><input name="shipExpenseRankAll" id="shipExpenseRankAll" value="1" type="checkbox" onClick="selectAll(this.form,this);"><label for="">全区</label><BR>
		<input name="shipExpenseRank1" id="shipExpenseRank1" value="1" type="checkbox"><label for="shipExpenseRank1">一区(上海)</label><BR>
		<input name="shipExpenseRank2" id="shipExpenseRank2" value="1" type="checkbox"><label for="shipExpenseRank2">二区(江苏  浙江  安徽  北京  广东)</label><BR>
		<input name="shipExpenseRank3" id="shipExpenseRank3" value="1" type="checkbox"><label for="shipExpenseRank3">三区(天津  河北  山东  福建)</label><BR>
		<input name="shipExpenseRank4" id="shipExpenseRank4" value="1" type="checkbox"><label for="shipExpenseRank4">四区(湖南  湖北  河南  江西  四川  重庆  山西)</label><BR>
		<input name="shipExpenseRank5" id="shipExpenseRank5" value="1" type="checkbox"><label for="shipExpenseRank5">五区(广西  陕西  云南  贵州  辽宁  吉林  黑龙江  海南  甘肃  青海  宁夏)</label><BR>
		<input name="shipExpenseRank6" id="shipExpenseRank6" value="1" type="checkbox"><label for="shipExpenseRank6">六区(新疆  西藏  内蒙)</label><BR>
		<s:hidden name="campaign.shipExpenseRank" id="shipExpenseRank" />
		</td>
	</tr>
	<tr>
		<th>* 最低订单金额</th>
		<td><s:textfield name="campaign.minOrderAmount" id="minOrderAmount" size="20"/></td>
	</tr>
	<tr>
		<th>折扣 kg</th>
		<td>
		<s:textfield name="campaign.discountData" id="discountData" size="20" maxlength="4"/>
		<%--
		<s:iterator value="menuPaymentType.options" var="opt">
			<c:out value="${opt.value.name}"/>: <s:textfield name="discountMap[%{#opt.key}]"/><br/>
		</s:iterator> --%>
		</td>
	</tr>
	<tr>
		<th>* 启用</th>
		<td>
			<input type="radio" name="campaign.enable" value="true" <c:if test="${campaign.enable}">checked</c:if>> 是　
			<input type="radio" name="campaign.enable" value="false" <c:if test="${!campaign.enable}">checked</c:if>> 否
	</tr>		
	<tr>
		<th>备注</th>
		<td><s:textarea name="campaign.memo" id="campaignMemo" rows="4" cols="60"/></td>
	</tr>
	
	<tr>
		<th>购物车提示html</th>
		<td><s:textarea name="campaign.shoppingHtml" id="shoppingHtml" rows="4" cols="60"/></td>
	</tr>
	<tr>
		<th>结帐页提示html</th>
		<td><s:textarea name="campaign.orderinfoHtml" id="orderinfoHtml" rows="4" cols="60"/></td>
	</tr>
	
	
	<tr>
		<td colspan="2">
			<div class="f-link">
				<input type="button" id="submit_button" value="储存修改">
<c:if test="${!empty campaign.uuid}">
				<input type="button" onclick="document.location='view.do'" value="回检视页">
</c:if><c:if test="${empty campaign.uuid}">
				<input type="button" onclick="document.location='search.do'" value="回活动查询页">
</c:if>
			</div>
		</td>
	</tr>		
</table>
</s:form>
